package com.example.mvp.mvppromote.presenter;

import com.example.mvp.mvppromote.base.BasePresenter;
import com.example.mvp.mvppromote.model.BandBean;
import com.example.mvp.mvppromote.network.Network;
import com.example.mvp.mvppromote.ui.iview.IBandView;

import rx.Observer;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wty on 2016/6/23 0023.
 */
public class BandPresenter extends BasePresenter<IBandView> {
    private IBandView iBandView;

    public BandPresenter(IBandView iBandView) {
        super(iBandView);
        this.iBandView = iBandView;
    }

    public void getBand(int page) {
        showDialog(iBandView.getMyContext());
        Subscription subscribe = Network.getBrandApi().getBandbean(page).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<BandBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onNext(BandBean bandBean) {
                        closeDialog();
                        // LogUtils.d(AppManager.getAppManager().currentActivity(), "------result-------" + new Gson().toJson(bandBean).toString());
                        iBandView.updateList(bandBean.getResult());
                    }
                });
        addSubscribe(subscribe);

    }

}
